package idv.kylechen.mathpractice;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.EditText;
import android.widget.Spinner;

public class MathPracticeActivity extends Activity {
    /** Called when the activity is first created. */
	int iNum1Digit = 2;
	int iNum2Digit = 2;
	int iOperator = 0;

	
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        Spinner sprNum1Digit = (Spinner)findViewById(R.id.spinnerNumber1Digit);
        //ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this,
        //		R.array.NumberDigits, android.R.layout.simple_spinner_item);
        ArrayAdapter<CharSequence> adapter1 = ArrayAdapter.createFromResource(this,
        		R.array.NumberDigits, R.layout.textview);        
        adapter1.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        //adapter.setDropDownViewResource(R.layout.textview);
        sprNum1Digit.setAdapter(adapter1);
        sprNum1Digit.setOnItemSelectedListener(new Spinner.OnItemSelectedListener(){
        		public void onItemSelected(AdapterView<?> adapterView , View view, int position, long id){
        			iNum1Digit = Integer.parseInt(adapterView.getSelectedItem().toString());
        		}
        		public void onNothingSelected(AdapterView<?>  arg0) {
        			
        	    }
        	});        
        
        Spinner sprNum2Digit = (Spinner)findViewById(R.id.spinnerNumber2Digit);
        sprNum2Digit.setAdapter(adapter1);
        sprNum2Digit.setOnItemSelectedListener(new Spinner.OnItemSelectedListener(){
    		public void onItemSelected(AdapterView<?> adapterView , View view, int position, long id){
    			iNum2Digit = Integer.parseInt(adapterView.getSelectedItem().toString());
    		}
    		public void onNothingSelected(AdapterView<?>  arg0) {
    			
    	    }
    	});           
        
        ArrayAdapter<CharSequence> adapter2 = ArrayAdapter.createFromResource(this,
        		R.array.Operators, R.layout.textview);        
        adapter2.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);    
        Spinner sprOperator = (Spinner)findViewById(R.id.spinnerOperator);
        sprOperator.setAdapter(adapter2);  
        sprOperator.setOnItemSelectedListener(new Spinner.OnItemSelectedListener(){
    		public void onItemSelected(AdapterView<?> adapterView , View view, int position, long id){
    			iOperator = position;
       		}
    		public void onNothingSelected(AdapterView<?>  arg0) {
    			
    	    }
    	});             
        
       
    }
    
    public void ExitClick(View target) {
    	this.finish();
    }
    
    public void StartClick(View target) {
    	EditText tv1 = (EditText) findViewById(R.id.editQuizCount);   	
    	int iQuizCount = Integer.parseInt(tv1.getText().toString());
    	Intent ni = new Intent();
    	ni.putExtra("QuizCount", iQuizCount);
    	ni.putExtra("Number1Digit", iNum1Digit);
    	ni.putExtra("Number2Digit", iNum2Digit);
    	ni.putExtra("Operator", iOperator);
    	ni.setClass(this, MathQuizActivity.class);
    	startActivity(ni);
    }   
    

}